package com.usian.admin.controller.v1;

import com.usian.admin.service.AdChannelService;
import com.usian.api.admin.AdChannelControllerApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *  频道管理
 */
@RestController
@RequestMapping("/api/v1/channel")
@CrossOrigin(origins = "*",allowCredentials = "true", allowedHeaders = "*")
public class AdChannelController implements AdChannelControllerApi{

    @Autowired
    private AdChannelService adChannelService;

    @PostMapping("/list")
    @Override
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto channelDto) {
        ResponseResult responseResult = adChannelService.findByNameAndPage(channelDto);
        return responseResult;
    }

    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody AdChannel channel) {
        return adChannelService.insert(channel);
    }

    @Override
    @PutMapping("/update")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return adChannelService.update(adChannel);
    }

    @Override
    @DeleteMapping("/del/{id}")
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        return adChannelService.deleteById(id);
    }
}
